<%= hidden_field_tag :material_type, scope[:material].getType() %>
<div class="new_form_content change_materials">
    <%- if repository_packages_map_from_config.empty? -%>
        <p class="warnings">No repositories found. Please <a href='<%=package_repositories_new_path%>'>add a package repository</a> first.</p>
    <%- end -%>

    <div class="new_form_item_block vtop" id="repository_div">
        <div class="new_form_label">
            <%= required_label(scope[:form], "repository", 'Repository') -%>
            <div class="inline_instruction">Choose a configured repository</div>
        </div>
        <div class="new_form_control required">
            <%= select_tag "material[package_definition[repositoryId]]", [], {:id => "repository", :class => "required"} %>
        </div>
        <div id="repository_error"></div>
    </div>

    <div class="new_form_item checkbox_row">
        <div class="new_form_label">
            <%= required_label(scope[:form], "material[packageId]", 'Package') -%>
        </div>
        <div class="new_form_control required">
            <div class="checkbox_row_inline">
                <%= radio_button_tag "material[create_or_associate_pkg_def]", "associate", true, :id => "chooseExisting" %>
                <label for="chooseExisting"><%= "Choose Existing" -%></label>
            </div>

            <div class="checkbox_row_inline">
                <%= radio_button_tag "material[create_or_associate_pkg_def]", "create", false, :id => "addNew" %>
                <label for="addNew"><%= "Define New" -%></label>
            </div>
        </div>
    </div>

    <div class="new_form_item">
        <div class="new_form_label"></div>
        <div class="new_form_control">
            <%= select_tag "material[packageId]", [], {:id => "package", :class => "required"} -%>
            <%= error_message_on(scope[:material], "material[package_definition[packageId]]", :css_class => "form_error") %>
        </div>
    </div>

    <%- state = (params[:material] && params[:material][:create_or_associate_pkg_def]) ? params[:material][:create_or_associate_pkg_def] : '' -%>
    <div class="package_definition">
        <div class="package_configuration">
            <% if @package_configuration %>
                <%- if (state == "associate" || state == "") -%>
                    <%= render :partial => 'admin/package_definitions/show_package_definition_for_new_pipeline_wizard', :locals => {:scope => {:package_configuration => @package_configuration}} %>
                <%- else -%>
                    <%= render :partial => 'admin/package_definitions/form_for_new_pipeline_wizard', :locals => {:scope => {:package_configuration => @package_configuration}} %>
                <%- end -%>
            <% end %>
        </div>
    </div>

</div>
<%= render :partial => 'shared/convert_tool_tips.html', :locals => {:scope => {}} %>

<script type="text/javascript">
    var data = <%== repository_packages_map_from_config.to_json %>;
    var repo = <%== scope[:material].getPackageDefinition() && scope[:material].getPackageDefinition().getRepository() ? scope[:material].getPackageDefinition().getRepository().getId().to_json  : "".to_json %>;
    var pkg = <%== scope[:material].getPackageDefinition() ? scope[:material].getPackageDefinition().getId().to_json : "".to_json %>;
    var initialState = <%== (params[:material] && params[:material][:create_or_associate_pkg_def]) ? params[:material][:create_or_associate_pkg_def].to_json : "".to_json %>;
    var showPackageDefPath = <%== package_definitions_show_for_new_pipeline_wizard_path(:repo_id => "$repoId$", :package_id => "$packageId$").to_json %>;
    var newPackageDefPath = <%== package_definitions_new_for_new_pipeline_wizard_path(:repo_id => "$repoId$").to_json %>;
    var pluginMissingErrorMessage = <%== "Associated plugin ''{0}'' not found. Please contact the Go admin to install the plugin.".to_json %>;
    Util.on_load(function () {
        new PackageMaterialCheckConnection("<%= package_definition_check_connection_path %>").bind(".new_form_content.change_materials", "#check_package", "#package_check_message");
        new PackageMaterialDefinitionForNewPipelineWizard(data, repo, pkg, showPackageDefPath, newPackageDefPath, pluginMissingErrorMessage).init(initialState);
    });
</script>
